<?php

namespace Jobs\Daemon\Netease;

/**
 * @name 登出回调
 * Class CallLogin
 * @package Jobs\Daemon\Netease
 */
class CallLogout extends \S\Thread\Worker {
    protected $whileSleep = 0;

    public function process() {
        try {
            $data = (new \Dao\Queue\Netease())->popLogout();
            if ($data) {
                //已存在的数据不在处理
                $info = (new \Data\Netease\Callback())->get($data['id']);
                if (!$info) {
                    //回调入库
                    (new \Data\Netease\Callback())->add($data);
//                    $msg = json_decode($data['msg'],true);
//                    $accid = $msg['accid'];
//                    $user_info = (new \Data\Netease\Im())->getByAccid($accid)['uid'];
//                    if($user_info['type'] == \Dao\Db\Netease\Im::TEACHER){
//                        (new \Service\Teacher\Info())->update($user_info['uid'], array('status'=> \Data\Teacher\Teacher::STATUS_OFFLINE));
//                    }
                }
            } else {
                sleep(5);
            }
        } catch (\Exception $e) {
            \S\Log\Logger::getInstance()->warning(array('错误码:' . $e->getCode(), '错误信息:' . $e->getMessage(), json_encode($data)));
        }
    }
}